﻿package mortal.game.view.vip.panel
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.vip.*;

    public class VipTopPart extends GSprite
    {
        private var _topBg:GBitmap;
        private var _vipLevel:BitmapNumberText;
        private var _rechargeBtn:GLoadingButton;
        private var _vipProgress:BaseProgressBar;
        private var _levelUpNeedMoney:GTextFiled;

        public function VipTopPart()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._topBg = UIFactory.gBitmap("", 0, 0, this);
            this._vipLevel = UIFactory.bitmapNumberText(124, 40, "VipLevelTitle.png", 49, 50, -6, this, 9, BitmapNumberText.Mid);
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.VipOpenBtn, 555, 49, 118, 44, this);
            this._rechargeBtn.drawNow();
            this._rechargeBtn.configEventListener(MouseEvent.CLICK, this.rechargeMoney);
            this._vipProgress = UICompomentPool.getUICompoment(BaseProgressBar);
            this._vipProgress.setBg(ImagesConst.VipProgressBg, true, 356, 34);
            this._vipProgress.setProgress(ImagesConst.VipProgress, true, 11, 10, 337, 15);
            this._vipProgress.setLabel(BaseProgressBar.ProgressBarTextNumber, 140, 7, 75, 8);
            this._vipProgress.x = 191;
            this._vipProgress.y = 53;
            addChild(this._vipProgress);
            this._levelUpNeedMoney = UIFactory.gTextField("", 214, 25, 300, 20, this, GlobalStyle.textFormatBai.center());
            this.updateReChargeAmount();
            this.updeteVipLevel();
            LoaderHelp.addResCallBack(ResFileConst.vipPanel, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._topBg.dispose(param1);
            this._topBg = null;
            this._vipLevel.dispose(param1);
            this._vipLevel = null;
            this._rechargeBtn.dispose(param1);
            this._rechargeBtn = null;
            this._vipProgress.dispose(param1);
            this._vipProgress = null;
            this._levelUpNeedMoney.dispose(param1);
            this._levelUpNeedMoney = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._topBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.VipTopBg);
            addChild(this._vipLevel);
            return;
        }// end function

        private function rechargeMoney(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.VipModule);
            return;
        }// end function

        private function updateReChargeTxt() : void
        {
            if (Cache.instance.vip.level == 10)
            {
                this._levelUpNeedMoney.text = Language.getString(35587);
            }
            else if (Cache.instance.vip.level == -1)
            {
                this._levelUpNeedMoney.htmlText = Language.getStringByParam(30707, VipConfig.instance.getVipReChargeMoneyByLevel(Cache.instance.vip.level) - Cache.instance.vip.reChargeMoney, "1");
            }
            else
            {
                this._levelUpNeedMoney.htmlText = Language.getStringByParam(30703, VipConfig.instance.getVipReChargeMoneyByLevel(Cache.instance.vip.level) - Cache.instance.vip.reChargeMoney, (Cache.instance.vip.level + 1));
            }
            return;
        }// end function

        public function updeteVipLevel() : void
        {
            this._vipLevel.text = VipUtil.vipLevel.toString();
            this.updateReChargeTxt();
            return;
        }// end function

        public function updateReChargeAmount() : void
        {
            var _loc_1:* = Cache.instance.vip.reChargeMoney;
            var _loc_2:* = VipConfig.instance.getVipReChargeMoneyByLevel(Cache.instance.vip.level);
            this._vipProgress.setValue(_loc_1 > _loc_2 ? (_loc_2) : (_loc_1), _loc_2);
            this.updateReChargeTxt();
            return;
        }// end function

    }
}
